package com.algorithm.java.string;

/***
 *                  _ooOoo_
 *                 o8888888o
 *                 88" . "88
 *                 (| -_- |)
 *                 O\  =  /O
 *              ____/`---'\____
 *            .'  \\|     |//  `.
 *           /  \\|||  :  |||//  \
 *          /  _||||| -:- |||||-  \
 *          |   | \\\  -  /// |   |
 *          | \_|  ''\---/''  |   |
 *          \  .-\__  `-`  ___/-. /
 *        ___`. .'  /--.--\  `. . __
 *     ."" '<  `.___\_<|>_/___.'  >'"".
 *    | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *    \  \ `-.   \_ __\ /__ _/   .-` /  /
 *======`-.____`-.___\_____/___.-`____.-'======
 *                  `=---='
 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 *        佛祖保佑       永无BUG
 ***/
import com.algorithm.utils.TextUtils;

/**
 * 字符串倒置:
 *  例子:
 *    Hello World --> dlroW olleH
 *    小仙女       --> 女仙小
 *
 * golang 实现方式.
 *  https://www.jianshu.com/p/6c648271bfbd
 */

public class StringInversion {

    public static String inversion(String src){
        if (TextUtils.isEmpty(src))
            return src;

        char[] strArray = src.toCharArray();
        int from = 0;
        int to = strArray.length - 1;

        //置换 , 使用中间变量,
        for (; from < to ; from++, to--){
            char temp       = strArray[from];
            strArray[from]   = strArray[to];
            strArray[to]     = temp;
        }

        return String.valueOf(strArray);
    }

}
